package com.example.piece.vm

import androidx.lifecycle.SavedStateHandle
import com.example.base.ext.LoadingView
import com.example.base.vm.BaseViewModel
import com.example.base.vm.OnSuccess
import com.example.piece.entity.AttentionEntity
import com.example.piece.entity.HelperJokeShareEntity
import com.example.piece.entity.HelperQQserviceEntity
import com.example.piece.entity.HelperQiniuTokenEntity
import com.example.piece.repository.HelperRepository

class HelperViewModel(savedStateHandle: SavedStateHandle) :
    BaseViewModel<HelperRepository>(savedStateHandle) {
    override fun createRepository(): HelperRepository = HelperRepository()

    /** 1
     * 意见反馈
     * @param brand 设备品牌
     * @param contact 联系方式
     * @param content 反馈的内容
     * @param pics 图片链接，多图用,分割，图片请先上传至七牛云
     * @param product 设备型号
     * @param release_version 系统版本号
     * @param version_code 当前版本code
     * @param version_name 当前版本号
     *
     * @see Unit
     */
    fun helperFeedback(loadingView: LoadingView?, brand: String,
                        contact: String,
                        content: String,
                        pics: String,
                        product: String,
                        release_version: String,
                        version_code: String,
                        version_name: String,onSuccess: OnSuccess<Unit>) =
        Launch(loadingView) {
            val result = repository.helperFeedback( brand,
                contact,
                content,
                pics,
                product,
                release_version,
                version_code,
                version_name)
            onSuccess(result)
        }


    /**
     * 2
     * 获取热搜关键词
     * @see  List<String>
     */
    fun helperHotSearch(loadingView: LoadingView?, onSuccess: OnSuccess<List<String>>) =
        Launch(loadingView) {
            val result = repository.helperHotSearch()
            onSuccess(result)
        }
    /**
     * 3
     * 获取jokes分享的内容
     *  @param id 被分享的段子id
     *  @see HelperJokeShareEntity
     */
    fun helperJokeShare(loadingView: LoadingView?,id: String, onSuccess: OnSuccess<HelperJokeShareEntity>) =
        Launch(loadingView) {
            val result = repository.helperJokeShare(id)
            onSuccess(result)
        }

    /**
     * 4
     * 段子分享成功计数
     * @param id 被分享的段子id
     * 分享段子成功之后需要调用此接口进行计数
     * @see Unit
     */
    fun helperJokeShareCount(loadingView: LoadingView?,id: String, onSuccess: OnSuccess<Unit>) =
        Launch(loadingView) {
            val result = repository.helperJokeShareCount(id)
            onSuccess(result)
        }

    /**
     * 5
     * 获取七牛云token
     * 上传头像或者上传图片段子或者上传视频段子之前需要获取七牛云的token
     * @param filename  文件名称，要带后缀
     * @param type     类型 type 0 获取普通token type 1 获取头像token
     * @see  HelperQiniuTokenEntity
     */
    fun helperQiniuToken(loadingView: LoadingView?,filename: String, type: String, onSuccess: OnSuccess<HelperQiniuTokenEntity>) =
        Launch(loadingView) {
            val result = repository.helperQiniuToken(filename,type)
            onSuccess(result)
        }
    /**
     * 6
     * 获取qq群信息
     *获取添加qq群的信息
     * @see HelperQQserviceEntity
     */
    fun helperQQservice(loadingView: LoadingView?, onSuccess: OnSuccess<HelperQQserviceEntity>) =
        Launch(loadingView) {
            val result = repository.helperQQservice()
            onSuccess(result)
        }

    /**
     * 7
     * 举报内容
     * 举报用户或者举报段子
     * @param content 举报的内容
     * @param report_tips  举报描述信息，预置的选择项
     * @param target_id  0 段子id 1 用户id
     * @param type  0 举报段子 1 举报用户
     * @see Unit
     */
    fun helperJokeShareCount(loadingView: LoadingView?, content: String, report_tips: String, target_id: String, type: String,onSuccess: OnSuccess<Unit>) =
        Launch(loadingView) {
            val result = repository.helperJokeShareCount(content, report_tips, target_id, type)
            onSuccess(result)
        }
    /**
     * 8
     * 获取分享用户的内容
     *@see HelperJokeShareEntity
     */
    fun helperUserShare(loadingView: LoadingView?,onSuccess: OnSuccess<HelperJokeShareEntity>) =
        Launch(loadingView) {
            val result = repository.helperUserShare()
            onSuccess(result)
        }
}